<script setup>
	const props = defineProps({
		carNum: {
			type: Number,
			default: 0
		},
		totalPrice: {
			type: Number,
			default: 1800
		},
		loading: {
			type: Boolean,
			default: false
		},
		collect: {
			type: Boolean,
			default: false
		},
		buyDisabled: {
			type: Boolean,
			default: false
		},
		mode: {
			type: String,
			default: 'default'
		}
	})
	
	const emit = defineEmits(['add', 'buy', 'home', 'car', 'collect'])
	
	function addCar() {
		emit('add')
	}
	function goBuy() {
		if(props.buyDisabled) {
			uni.showToast({
				icon: 'none',
				title: '最低1000元起订'
			})
		} else emit('buy')
	}
	function goHome() {
		emit('home')
	}
	function goCar() {
		emit('car')
	}
	function goCollect() {
		emit('collect')
	}
</script>

<template>
	<view class="bar-content">
		<view class="bar-left">
			<view class="car-box" v-if="mode === 'default'">
				<view class="num-box" @click="goCar">
					<uv-icon name="https://jhgk-1307466921.cos.ap-shanghai.myqcloud.com/opt/AppCollect/PersonJkzImg/2025-02-17/1739762490897_car-bar.png" size="40" />
					<veiw class="car-num" v-if="props.carNum > 0">{{props.carNum}}</veiw>
				</view>
				<view class="total-price">{{props.totalPrice? props.totalPrice.toFixed(2) : 0.00}}</view>
			</view>
			<view class="collect-box" v-else-if="mode === 'collect'">
				<view class="func-item" @click="goHome">
					<uv-icon name="https://jhgk-1307466921.cos.ap-shanghai.myqcloud.com/opt/AppCollect/PersonJkzImg/2025-02-17/1739775114290_bar-home.png" size="40"></uv-icon>
					<text>首页</text>
				</view>
				<view class="func-item" @click="goCar">
					<uv-icon name="https://jhgk-1307466921.cos.ap-shanghai.myqcloud.com/opt/AppCollect/PersonJkzImg/2025-02-17/1739775224793_bar-car.png" size="40"></uv-icon>
					<text>购物车</text>
					<veiw class="car-num" v-if="props.carNum > 0">{{props.carNum > 99 ? '99+' : props.carNum}}</veiw>
				</view>
				<view class="func-item" :class="loading? 'btn-disabled' : ''" @click="goCollect">
					<uv-icon :name="props.collect? 'star-fill' : 'star'" color="#999999" size="42"></uv-icon>
					<text>收藏</text>
				</view>
			</view>
		</view>
		<view :class="['bar-btn', loading? 'btn-disabled' : '']">
			<view class="btn-add" @click="addCar">加入购物车</view>
			<view :class="['btn-buy', buyDisabled? 'btn-disabled' : '']" @click="goBuy">立即购买</view>
		</view>
	</view>
</template>

<style lang="scss" scoped>
	.bar-content{
		height: 112rpx;
		background-color: #FFFFFF;
		padding: 0 24rpx;
		display: flex;
		align-items: center;
		gap: 10rpx;
		.bar-left{
			flex: 1;
			.car-box{
				display: flex;
				align-items: center;
				gap: 32rpx;
				.num-box{
					flex-shrink: 0;
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					background-color: #FF3E49;
					display: flex;
					justify-content: center;
					align-items: center;
					position: relative;
					.car-num{
						position: absolute;
						right: -10rpx;
						top: -10rpx;
						width: 32rpx;
						height: 32rpx;
						line-height: 32rpx;
						text-align: center;
						background-color: #FA3F00;
						border-radius: 50%;
						font-size: 16rpx;
						color: #FFFFFF;
						font-weight: 600;
						border: 1rpx solid #FFFFFF;
					}
				}
				.total-price {
					flex: 1;
					font-weight: 600;
					font-size: var(--theme-lg);
					line-height: var(--theme-lg-line);
					color: #FF0D0D;
					&::before{
						content: "¥";
						font-size: 60%;
					}
				}
			}
			.collect-box{
				display: flex;
				align-items: center;
				gap: 16rpx;
				.func-item{
					flex: 1 0;
					display: flex;
					flex-direction: column;
					align-items: center;
					gap: 4rpx;
					color: #999999;
					font-size: var(--theme-sm);
					line-height: var(--theme-sm-line);
					position: relative;
					.car-num{
						position: absolute;
						right: 10rpx;
						top: -10rpx;
						width: 32rpx;
						height: 32rpx;
						line-height: 32rpx;
						text-align: center;
						background-color: #FA3F00;
						border-radius: 50%;
						font-size: 16rpx;
						color: #FFFFFF;
						font-weight: 600;
					}
				}
				
			}
		}
		.bar-btn{
			flex-shrink: 0;
			display: flex;
			line-height: 80rpx;
			color: #FFFFFF;
			font-weight: 600;
			text-align: center;
			border-radius: 80rpx;
			overflow: hidden;
			.btn-add{
				width: 204rpx;
				height: 80rpx;
				background: linear-gradient( 102deg, #FA3F00 0%, #FF7445 100%);
			}
			.btn-buy{
				width: 176rpx;
				height: 80rpx;
				background: linear-gradient( 245deg, #F92E1D 0%, #FF3E49 100%);
			}
		}
	}
	.btn-disabled{
		opacity: 0.4;
	}
</style>